﻿using Appliaction.Dto.Sinv;
using Appliaction.IAppServices.Sinv;
using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers.Sinv
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Sinv_Sale_OutboundController : ControllerBase
    {
        private readonly ISinv_Sale_OutboundService sinv_Sale_OutboundService;
        private readonly IMapper mapper;

        public Sinv_Sale_OutboundController(ISinv_Sale_OutboundService sinv_Sale_OutboundService,IMapper mapper)
        {
            this.sinv_Sale_OutboundService = sinv_Sale_OutboundService;
            this.mapper = mapper;
        }

        /// <summary>
        /// 分页条件查询销售出库信息及其明细
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="customerName"></param>
        /// <param name="orderCode"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetSinv_Sale_Outbound_Infos(int currentPage, int pageSize, string? customerName, string? orderCode, int orderStatus, char auditStatus)
        {
            return new JsonResult(sinv_Sale_OutboundService.GetSinv_Sale_Outbound_Infos(currentPage,pageSize,customerName,orderCode,orderStatus,auditStatus));
        }

        /// <summary>
        /// 条件查询销售出库总数
        /// </summary>
        /// <param name="customerName"></param>
        /// <param name="orderCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Sinv_Sale_OutboundCountAsync(string? customerName, string? orderCode, int orderStatus, char auditStatus)
        {
            return new JsonResult(await sinv_Sale_OutboundService.Sinv_Sale_OutboundCountAsync(customerName,orderCode,orderStatus,auditStatus));
        }

        /// <summary>
        /// 逻辑删除销售出库信息并修改销售订单明细的预计出库数量
        /// </summary>
        /// <param name="sinv_CustomerDelDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sinv_Sale_OutboundDelAsync(Sinv_Sale_OutboundDelDto sinv_CustomerDelDto)
        {
            return new JsonResult(await sinv_Sale_OutboundService.Sinv_Sale_OutboundDelAsync(sinv_CustomerDelDto));
        }

        /// <summary>
        /// 添加销售出库信息及其详情
        /// </summary>
        /// <param name="saleOutboundWithDetailsDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> Sinv_Sale_OutboundAddAsync([FromBody] SaleOutboundWithDetailsDto<Sinv_Sale_OutboundAddDto> saleOutboundWithDetailsDto)
        {
            return new JsonResult(await sinv_Sale_OutboundService.Sinv_Sale_OutboundAddAsync(saleOutboundWithDetailsDto));
        }

        /// <summary>
        /// 根据销售出库编号查询对应销售出库信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSinv_Sale_OutboundByCodeAsync(string code)
        {
            return new JsonResult(await sinv_Sale_OutboundService.GetSinv_Sale_OutboundByCodeAsync(code));
        }

        /// <summary>
        /// 根据销售出库编号查询销售出库明细
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSinv_Sale_Outbound_DetailsByCodeAsync(string code)
        {
            return new JsonResult(await sinv_Sale_OutboundService.GetSinv_Sale_Outbound_DetailsByCodeAsync(code));
        }

        /// <summary>
        /// 修改销售出库信息及其详情
        /// </summary>
        /// <param name="saleOutboundWithDetailsUpdateDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sinv_Sale_OutboundUpdateAsync([FromBody] SaleOutboundWithDetailsUpdateDto saleOutboundWithDetailsDto)
        {
            return new JsonResult(await sinv_Sale_OutboundService.Sinv_Sale_OutboundUpdateAsync(saleOutboundWithDetailsDto));
        }

        /// <summary>
        /// 修改销售出库订单审核状态，减少库存，增加销售明细出库数量，修改销售订单出库状态
        /// </summary>
        /// <param name="sinv_Sale_Outbound"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sinv_Sale_OutboundAuditUpdateAsync(Sinv_Sale_OutboundAuditUpdateDto sinv_Sale_Outbound)
        {
            return new JsonResult(await sinv_Sale_OutboundService.Sinv_Sale_OutboundAuditUpdateAsync(sinv_Sale_Outbound));
        }
    }
}
